<template>
  <div>
    <ArticleAdd :form="form" @editArticle="editArticle" :fileList="image_path"></ArticleAdd>
  </div>
</template>
<script>
import { ArticleAdd } from "../../components/index";
export default {
  components: {
    ArticleAdd
  },
  data() {
    return {
      form: {},
      image_path: []
    };
  },
  mounted() {
    let { id } = this.$route.query;
    this.$http({
      url: "api/articlelist",
      params: {
        id
      }
    }).then(res => {
      this.form = res.data[0];
      if (res.data[0].description_image_path != "") {
        this.image_path = [
          { name: "", url: res.data[0].description_image_path }
        ];
      }
    });
  },
  methods: {
    editArticle(data) {
      console.log(data);
      this.$http({
        url: "api/edit",
        method: "post",
        data,
      }).then(res => {
        console.log(res);
        if (res.data.code === 1) {
          this.$message({
            message: res.data.message,
            type: "success"
          });
          // 延时跳转
          setTimeout(() => {
            this.$router.push("/article");
          }, 1000);
        } else {
          this.$message({
            message: res.data.message,
            type: "warning"
          });
        }
      });
    }
  }
};
</script>
<style lang='less'>
</style>
